package code.ws_common_scene.texturedata
{
	import code.ws_common_utils.SysUtils;
	import code.ws_common_utils.UrlUtils;
	
	import flash.utils.Dictionary;

	/**
	 * 特效配置解析池 
	 * @author qiangchen
	 * 
	 */	
	public class EftTextureDataPool
	{
		private static var _dic:Dictionary = new Dictionary();
		
		/**
		 * 获取数据池 
		 * @return 
		 * 
		 */		
		public static function get dic():Dictionary
		{
			return _dic;
		}
		
		
		/**
		 * 解析 （特效定位单方向 ）
		 * @param xml
		 * 
		 */		
		public static function analyze( xml:XML ):void
		{
			if( xml == null ) return;
			var lens:int = xml.info.length();
			for( var i:int=0; i<lens; i++ )
			{
				var style:String = xml.info[i].nameid;
				if( _dic[style] ) continue;
				
				var _xml:XML = XML(xml.info[i].actionDatas);
				var _childNum:int = _xml.elements().length();
				var _frameCount:int = _xml.@frameCount;
				if( _frameCount != _childNum ) continue;

				var _frameRate:int = _xml.@frameRate;
				
				var playData:TexturePlayData = new TexturePlayData();
				playData.style = style;
				playData.direction = 0;
				playData.frameCount = _frameCount;
				playData.frameRate = _frameRate;
				playData.isLoop = true;
				
				for( var j:int=0; j<_childNum; j++ )
				{
					var _$xml:XML = XML( _xml.child( "f" + j ) );
					var texture:Textures = new Textures();
					texture.w = _$xml.@width;
					texture.h = _$xml.@height;
					texture.scal = 1;
					texture.offx = _$xml.@x;
					texture.offy = _$xml.@y;
					texture.key = playData.style;
					texture.path = UrlUtils.getEftUrl( texture.key );
					texture.key += ( "_" + int(j+1) );
					playData.framesTimeLine.push( playData.frameRate * 1000 / SysUtils.stage.frameRate );
					playData.textures.push( texture );
				}
				
				playData.ini();
				_dic[style] = playData;
			}
		}
		
		
		
		/**
		 * 获取特效池 
		 * @param key
		 * @return 
		 * 
		 */		
		public static function getPlayData( key:String ):TexturePlayData
		{
			return _dic[key];
		}
	}
}